package com.ewhale.feitengguest.presenter.shop.message

import com.ewhale.feitengguest.api.ApiHelper
import com.ewhale.feitengguest.dto.ShopMessageDto
import com.ewhale.feitengguest.view.shop.message.SMessageView
import com.simga.library.base.IPresenter
import com.simga.library.http.APIException

/**
 * 作者：SimGa
 * 日期：2020/1/2
 * 时间：11:17
 * 包名：com.ewhale.feitengguest.presenter.shop.task
 */
class SMessagePresenter : IPresenter() {
    fun getShopMessage(pageNumber: Int, type: Int) {
        request(1, ApiHelper.MESSAGE_API.getShopMessage(pageNumber, 10, type), null)
    }

    override fun <T> onNext(postCode: Int, result: T, data: Any?) {
        super.onNext(postCode, result, data)
        when (postCode) {
            1 -> {
                (mView as SMessageView).showMessageList(result as List<ShopMessageDto>)
            }
        }
    }

    override fun otherException(postCode: Int, data: Any, e: APIException?) {
        super.otherException(postCode, data, e)
        mView.showErrorMessage(postCode, e!!.code, e.displayMessage)
    }
}
